<?php

namespace App\Admin\Controllers;

use App\Company;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class CompanyController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('用户企业管理')
            ->description('列表')
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('用户企业管理')
            ->description('详情')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('用户企业管理')
            ->description('编辑')
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('用户企业管理')
            ->description('新增')
            ->body($this->form());
    }
    /**
     * @param Grid $grid
     * @return Grid
     */
    public function grid()
    {
        $grid = new Grid(new Company);
        $grid->id('ID');
        $grid->company_name('公司名称');
        $grid->company_desc('公司简介');
        $grid->is_check('状态')->using(['1' => '是', '0' => '否']);;
        $grid->company_contacts('联系人');
        $grid->company_phone('联系电话');
        $grid->company_area('地址');
        $grid->created_at('添加时间');
        $grid->updated_at('编辑时间');
        return $grid;
    }


    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Company::findOrFail($id));

        $show->id('ID');
        $show->company_name('公司名称');
        $show->company_desc('公司简介');
        $show->is_check('状态')->using(['1' => '是', '0' => '否']);
        $show->company_contacts('联系人');
        $show->company_phone('联系电话');
        $show->company_area('地址');
        $show->created_at('添加时间');
        $show->updated_at('编辑时间');

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Company);
        $form->text('company_name','公司名称')->rules("required|unique:admin_company,company_name");
        $form->text('company_desc','公司简介');
        $form->radio('is_check','公司状态')->options(['0' => '否', '1'=> '是'])->default('1');
        $form->text('company_contacts','公司联系人');
        $form->text('company_phone','公司电话');
        $form->text('company_area','公司地址');
        return $form;
    }
}
